package com.contory.ssn_lgnd.app.maingame;

import java.util.LinkedList;
import java.util.Random;

import android.util.Log;

import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;

public class EnemyGroup implements UpdatePtr, DrawPtr{
	LinkedList<Enemy> enemyList;
	final Player player; 
	final ColisionManager cm; 
	final Fire fire; 
	final Random rand;
	final ParticleEffectGroup pEffectGroup;
	final TextureEffectGroup texEffectGroup;
	final int ID;
	boolean createdBool;
	
	public EnemyGroup(Player player, ColisionManager cm, Fire fire, Random rand, ParticleEffectGroup pEffectGroup, TextureEffectGroup texEffectGroup, int ID){
		enemyList = new LinkedList<Enemy>();
		this.player = player;
		this.cm = cm;
		this.fire = fire;
		this.rand = rand;
		this.pEffectGroup = pEffectGroup;
		this.texEffectGroup = texEffectGroup;
		this.ID = ID;
		createdBool = false;
	}
	
	public int getGroupID(){
		return ID;
	}

	public Enemy addEnemy(float strX, float strY){
		createdBool = true;
		//Log.d("1", "1");
		Enemy enemy = new Enemy(strX, strY, player, cm, fire, rand, this, pEffectGroup.addEffect(), texEffectGroup);
		enemy.setGroupId(ID);
		enemyList.add(enemy);
		cm.addDynamicColiObj(enemy);
		return enemy;
	}
	
	public void removeEnemy(Enemy chdEnemy){
		enemyList.remove(chdEnemy);
		cm.removeDynamicObj(chdEnemy);
	}
	
	public void clear(){
		enemyList.clear();
	}
	
	public int getSize(){
		return enemyList.size();
	}

	@Override
	public void draw(SpriteBatcher batcher) {
		for(int i = 0; i < enemyList.size(); i++){
			enemyList.get(i).draw(batcher);
		}
	}
	
	@Override
	public void update(float deltaTime) {
		for(int i = 0; i < enemyList.size(); i++){
			enemyList.get(i).update(deltaTime);
		}
	}
	
	public boolean getEmptyBool(){
		return (enemyList.size() <= 0 ? true : false) && createdBool;
	}
}
